/**
 * @ClassName LC1394
 * @Author ykx
 * @Date 2024/7/6 11:23
 * @Version 1.0
 */
public class LC1394 {
    public static void main(String[] args) {

    }

    public int findLucky(int[] arr) {
        int result = -1;
        int min = arr[0], max = arr[0];
        for (int i : arr) {
            if (i >= max) {
                max = i;
                continue;
            }
            if (i <= min) {
                min = i;
            }
        }

        int[] count = new int[max - min + 1];
        for (int i : arr) {
            count[i - min]++;
        }

        for (int i = count.length - 1; i >= 0; i--) {
            if (count[i] - i == 1) {
                return count[i];
            }
        }

        return result;
    }

}
